import time
import requests
import re
import json

# 查询物品
with open('./programming.txt', 'r', encoding='utf-8') as file_object:
    tmp = file_object.read()
    query = re.split('\n', tmp)
    print(query)

for i in range(0, len(query)):

    tmp = re.split('\t', query[i])
    name = tmp[0]
    rubbishType = tmp[1]
    if rubbishType == '可回收垃圾':
        rubbishType = 0
    elif rubbishType == '湿垃圾':
        rubbishType = 1
    elif rubbishType == '有害垃圾':
        rubbishType = 2
    elif rubbishType == '干垃圾':
        rubbishType = 3
    else:
        continue

    # 后端接口
    baseurl = ''

    data = {
        'name': name,
        'type': rubbishType
    }

    res = requests.post(baseurl, data=data)

    time.sleep(0.5)
